package api

import (
	"gateway-api/basic/config"
	__ "gateway-api/basic/proto"
	"gateway-api/handler/request"
	"github.com/gin-gonic/gin"
	"net/http"
)

func CreateReserveStock(c *gin.Context) {
	var param request.CreateReserveStockReq
	if err := c.ShouldBind(&param); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": 400,
			"mes":  "参数错误",
		})
		return
	}
	r, err := config.UserCline.CreateReserveStock(c, &__.CreateReserveStockReq{
		Username:       param.Username,
		IdCard:         param.IdCard,
		Phone:          param.Phone,
		HospitalId:     param.HospitalId,
		PackageId:      param.PackageId,
		ReserveDate:    param.ReserveDate,
		TotalStock:     param.TotalStock,
		UsdStock:       param.UsdStock,
		RemainingStock: param.RemainingStock,
	})
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": 400,
			"mes":  err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"mes":  "预约成功",
		"data": r,
	})
	return
}

func ReserveStockList(c *gin.Context) {
	var param request.ReserveStockListReq
	if err := c.ShouldBind(&param); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": 400,
			"mes":  "参数错误",
		})
		return
	}
	r, err := config.UserCline.ReserveStockList(c, &__.ReserveStockListReq{})
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": 400,
			"mes":  err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"mes":  "三十天预约成功",
		"data": r,
	})
	return
}
